package com.buddy.summary.code.stream;

import org.junit.Test;

import java.util.Comparator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

public class LambdaDemo {
    @Test
    public void test1(){
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("AAAAAA");
            }
        };
        runnable.run();
    }

    @Test
    public void test2(){
        Runnable runnable = ()->System.out.println("BBBBB");
        runnable.run();
    }

    @Test
    public void test3(){
        Consumer<String> consumer = e->System.out.println(e);
        consumer.accept("aaaa");
    }

    @Test
    public void test4(){
        Comparator<Integer> comparator = (x,y)->{
            return Integer.compare(x,y);
        };

        int compare = comparator.compare(100,200);
        System.out.println(compare);
    }

    @Test
    public void test5(){
        Comparator<Integer> comparator = (x,y)->Integer.compare(x,y);
        System.out.println(comparator.compare(1,2));
        Comparator<Integer> comparator1 = Integer::compareTo;
        System.out.println(comparator1.compare(2,2));
    }

    @Test
    public void test6(){
        Supplier<String> stringSupplier = ()->"533333".substring(0,2);
        System.out.println(stringSupplier.get());
    }

    @Test
    public void test7(){
        Function<String,String> function = (x)->x.substring(0,2);
        System.out.println(function.apply("12222"));
    }

    @Test
    public void test8(){
        Predicate<String> predicate = (x)->x.length()>5;
        System.out.println(predicate.test("abc"));
    }

}
